package main

import (
	"bytes"
)

/**
 * @Author: DengLibin
 * @Date: Create in 2023-01-17 15:51:47
 * @Description:
 */
/**
 * @Author: DengLibin
 * @Date: Create in 2023-01-17 15:51:51
 * @Description:
 */
func toHex(num int) string {
	if num == 0 {
		return "0"
	}
	arr := []byte{
		'0', '1', '2', '3',
		'4', '5', '6', '7',
		'8', '9', 'a', 'b',
		'c', 'd', 'e', 'f',
	}
	//转无符号类型
	var x uint32 = uint32(num)
	var mod uint32
	var buffer bytes.Buffer
	for x > 0 {
		mod = x % 16
		x /= 16
		s := buffer.String()
		buffer.Reset()
		buffer.WriteByte(arr[mod])
		buffer.WriteString(s)

	}

	return buffer.String()
}
